package com.afkx.oop.phone;

/**
 * @ClassName 手机类
 * @Description TODO
 * @Author Kx
 * @Date 2025/2/28 9:54
 * @Version 1.0
 */
public class Phone {
    private String brand; // 手机品牌
    private double price; // 手机价格
    private String name; // 手机名称
    private String[] contactList; // 联系人列表

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String[] getContactList() {
        return contactList;
    }

    public void setContactList(String[] contactList) {
        if (contactList.length > 10){
            System.out.println("联系人列表不能超过10个");
        }else {
            this.contactList = contactList;
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
    public Phone(){

    }

    public Phone(String brand, String[] contactList, String name, double price) {
        this.brand = brand;
        this.contactList = contactList;
        this.name = name;
        this.price = price;
    }

    // 方法
    public void call(){
        System.out.println(this.name + "正在上网");
    }

    public void sendMessage(String name,String message){
        boolean flag = false;
        for (int i = 0; i < this.contactList.length; i++) {
            if (this.contactList[i].equals(name)){
                System.out.println(this.name + "正在给" + name + "发送信息：" + message);
                flag = true;
                break;
            }
        }
        if (!flag){
            System.out.println("给 匿名用户发送:" + message);
        }
    }
}
